//C10:ep10_23.c: function pointer,used like this:
// find max value between a and b.
// find min value between a and b.
// get the sum of a and b.
#include <stdio.h>

int max(int, int);
int min(int, int);
int add(int, int);
void process(int ,int ,int(*fun)(int, int));

int main(void)
{
    int a, b;
    printf("Enter a and b:\n");
    scanf("%d%d",&a, &b);
    
    printf("max = ");
    process(a, b, max);

    printf("min = ");
    process(a, b, min);

    printf("sum = ");
    process(a, b, add);

    return 0;
} 

int max(int x, int y)
{
    int z;
    if(x > y)
    {
        z = x;
    }
    else
    {
        z = y;
    }

    return z;
}

int min(int x, int y)
{
    int z;
    if(x < y)
    {
        z = x;
    }
    else
    {
        z = y;
    }

    return z;
}

int add(int x, int y)
{
    int z;
    z = x + y;
    return z;
}

void process(int x, int y, int (*fun)(int, int))
{
    int result;
    result = (*fun)(x, y);
    printf("%d\n", result);
}